import { Table, Card, Button, Row } from 'dw-mx';
import React, { useState } from 'react';
import moment from 'moment';
import {request} from 'dw-mx-request'


export default function ExpertMaintain() {

    const [tableData, setTableData] = useState([]);
    const [selectedRowKeys,setSelectedRowKeys] = useState([])

    const handleQuery = async () => {
        const result = await request('/mock/zjgl/queryList')
        for (let i = 0; i <result.data.length; i++) {
            result.data[i].bge626=moment(result.data[i].bge626).format("YYYY-MM-DD");
            result.data[i].bge627=moment(result.data[i].bge627).format("YYYY-MM-DD");
            result.data[i].bge630=moment(result.data[i].bge630).format("YYYY-MM-DD");
        }
        setTableData(result.data);
    };

    const handleReset = () => {
        const newdata = tableData;
        const result = newdata.filter(item => {
            if(selectedRowKeys.indexOf(item.bge61n) == -1){
                return item
            }
        })
        setTableData(result)
        setSelectedRowKeys([])
    };

    const rowSelection = {
        selectedRowKeys,
        onChange: (selectedRowKeys) => {
            setSelectedRowKeys(selectedRowKeys)
        }
    }

    const columns = [
        {
            title: '姓名',
            dataIndex: 'aac003',
        },

        {
            title: '证件号码',
            dataIndex: 'aac147',

        },
        {
            title: '专家任职开始日期',
            dataIndex: 'bge626',

        },
        {
            title: '专家任职结束日期',
            dataIndex: 'bge627',

        },
        {
            title: '信息录入时间',
            dataIndex: 'bge630',

        },
    ];

    const tabPagination = {
        pageSize: 5,
        showQuickJumper: true,
    }

    return(
        <>
            <Card title='查询结果'>
                <Row justify="end">
                    <Button type={"primary"} onClick={handleQuery} style={{marginBottom:'13px'}}>查询</Button>

                    <Button type={"primary"} onClick={handleReset} style={{marginBottom:'13px'}}>删除</Button>
                </Row>
                <Table
                    rowSelection={{ ...rowSelection, }}
                    rowKey={'bge61n'}
                    columns={columns}
                    dataSource={tableData}
                    scroll={{ x: 1500, y: 300 }}
                    pagination={tabPagination}
                />
            </Card>
        </>
    );
}